package com.ylx.excel.excel.handler;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: <br/>
 * date: 2022/9/2 11:30<br/>
 * Excel读取监听器
 * @author yanglixin2<br />
 */
@Slf4j
public class ExcelListener<T> extends AnalysisEventListener<T> {


    /**全部的实体类*/
    private final List<T> allList = new ArrayList<>();

    /**
     * 读取数据
     */
    @Override
    public void invoke(T t, AnalysisContext analysisContext) {
        allList.add(t);
    }

    /**
     * 读取数据完毕
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("数据读取完毕!");
    }

    /**
     * 获取读到的全部数据
     * @author yanglixin2
     */
    public List<T> getData() {
        return allList;
    }
}

